﻿@{
    ViewBag.Title = "任务日志";
    Layout = "~/Views/Shared/_Index.cshtml";
}
@using Raffles.OA.Data
@using Raffles.OA.Utility
<section class="content">
    <div class="row">
        <div class="col-xs-12"> 
            <div class="box box-info">
                <div class="box-body">
                    <div class="table-responsive">
                        <div class="btn-group-sm" id="toolbar" role="group">
                            <a id="btnClean" class="btn btn-danger" onclick="cleanLog()"><i class="fa fa-trash"></i> 清空</a>
                            <div class="col-sm-3 pull-right">
                                <div class="input-group input-group-sm">
                                    <input type="text" id="keyWord" col="KeyWord" class="form-control" placeholder="请输入任务名称" />
                                    <div class="input-group-btn">
                                        <button type="button" id="btnSearch" class="btn btn-primary" onclick="searchGrid()"><i class="fa fa-search"></i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <table id="gridTable" class="table table-hover table-striped text-nowrap">
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">

    $(function () {
        initGrid();
    });

    function initGrid() {
        $('#gridTable').frameTable({
            url: '@Url.Action("GetPageListJson", "AutoJobLog")',
            columns: [
                { field: 'Id', title: 'Id', visible: false },
                { field: 'JobGroupName', title: '任务组', halign: "center", align: "center" },
                { field: 'JobName', title: '任务名称', halign: "center", align: "center" },
                {
                    field: 'LogStatus', title: '执行状态', halign: "center", align: "center",
                    formatter: function (value, row, index) {
                        if (value ==@((int)OperateStatusEnum.Success)) {
                            return '<span class="label label-success">' + "@OperateStatusEnum.Success.GetDescription()" + '</span>';
                        } else {
                            return '<span class="label label-danger">' + "@OperateStatusEnum.Fail.GetDescription()" + '</span>';
                        }
                    }
                },
                { field: 'Remark', title: '执行结果', halign: "center", align: "center" },
                { field: 'CreateOn', title: '执行时间', halign: "center", align: "center"}
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').frameTable('getPagination', params);
                var queryString = $('#toolbar').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search'); 
    }
    //日志清空
    function cleanLog() {
        frame.confirm('确定要清空所有调度执行日志吗?', function () {
            frame.ajax({ 
                url: '@Url.Action("LogClean", "AutoJobLog")',
                type: "post",
                success: function (obj) {
                    if (obj.success) {
                        frame.msgSuccess(obj.message);
                        searchGrid();
                    }
                    else {
                        frame.msgError(obj.message);
                    }
                }
            });
        });
    }
</script>